/*
 * Copyright 2012-2025 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.assertj.core.api.recursive.comparison;

import java.util.Set;

import org.assertj.core.annotation.Beta;
import org.assertj.core.api.RecursiveComparisonAssert;

/**
 * Defines how objects are introspected in the recursive comparison, the main operations it specifies are:
 * <ul>
 * <li>how to traverse the graph of nodes to compare</li>
 * <li>how to get a child node value</li>
 * </ul>
 */
@Beta
public interface RecursiveComparisonIntrospectionStrategy {

  /**
   * Returns the names of the children nodes of the given object that will be used in the recursive comparison.
   * <p>
   * A typical implementation could look at the object fields or properties.
   *
   * @param node the object to get the child nodes from
   * @return the names of the children nodes of the given object
   */
  Set<String> getChildrenNodeNamesOf(Object node);

  /**
   * Returns the value of the given object child node, the child node being identified by the childNodeName parameter.
   * <p>
   * It's the implementor choice how to resolve the child node value, a typical implementation consists of considering
   * childNodeName to be a field name and then use introspection to read the field value, but if the object is a Map
   * the implementation could consider the child node name to be a key of the map.
   *
   * @param childNodeName the child node identifier
   * @param object        the object to read the child node from
   * @return the object child node value
   */
  Object getChildNodeValue(String childNodeName, Object object);

  /**
   * Returns a human-readable description of the strategy to be used in error messages.
   * <p>
   * The default implementation returns {@code this.getClass().getSimpleName()}.
   *
   * @return a description of the strategy
   */
  default String getDescription() {
    return this.getClass().getSimpleName();
  }

  /**
   * Makes the recursive comparison to ignore <a href="https://docs.oracle.com/javase/specs/jvms/se6/html/Concepts.doc.html#18858">transient</a> fields.
   * <p>
   * Inherits from {@link AbstractRecursiveComparisonIntrospectionStrategy} to benefit from the default implementation.
   * <p>
   * See {@link RecursiveComparisonAssert#ignoringTransientFields()} for examples.
   */
  default void ignoreTransientFields() {
    // do nothing by default
  }

  /**
   * Returns whether transient fields are ignored in the recursive comparison, this is false by default.
   *
   * @return whether transient fields are ignored in the recursive comparison.
   */
  default boolean shouldIgnoreTransientFields() {
    return false;
  }
}
